/*******************************************************************************
 * 文件名: EncodingFilter.java
 * 描    述: 中文字符集过滤器
 * 创建人: Dean Huang(hudi-112@163.com)
 * 日　期: 2016-05-10
 * 描　述: 文件描述
 * 版　本: 1.0
 *******************************************************************************/

package com.z1.core.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EncodingFilter implements Filter {

	private final String ENCODING_UTF8 = "utf-8";
	
	@Override
	public void init(FilterConfig arg0) throws ServletException {
	}
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
		((HttpServletRequest)req).setCharacterEncoding(ENCODING_UTF8);
		((HttpServletResponse)resp).setCharacterEncoding(ENCODING_UTF8);
	    chain.doFilter(req, resp);
	}

	@Override
	public void destroy() {
	}

}
